package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliOSSUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * 处理文件上传
 */
@Slf4j
@RestController
@RequestMapping("upload")
public class UploadController {


    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping
    @SneakyThrows //抑制异常
    public Result upload(MultipartFile image) {
        log.info("临时文件 {}", image);
        //调用AliOSSutils，一定要注意，返回的是oss中图片的访问地址
        String url = aliOSSUtils.upload(image);
        return Result.success(url);
    }


}
